package com.atguigu.controller;

import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: ParameterTestController
 * Package: com.atguigu.controller
 * Description:
 *
 * @Author Root
 * @Create 2023/3/24 15:09
 * @Version 1.0
 */
@RestController
public class ParameterTestController {

    @GetMapping("/car/{id}/{username}")
    public Map<String,Object> getCar(@PathVariable("id") String id,
                                     @PathVariable("username") String username,
                                     @PathVariable Map<String,String> pv,
                                     @RequestHeader("User-Agent") String userAgent,
                                     @RequestHeader Map<String,String> allHeader,
                                     @RequestParam("age") Integer age,
                                     @RequestParam("interests")List<String> interests,
                                     @RequestParam MultiValueMap<String,String> params
//                                     @CookieValue("_ga") String _ga,
                                     ) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("pv",pv);
        map.put("allHeader",allHeader);
        map.put("age",age);
        map.put("interests",interests);
        map.put("params",params);
//        map.put("_ga",_ga);
        return map;
    }


    @PostMapping("/save")
    public Map postMethod(@RequestBody String context){
        HashMap<String, Object> map = new HashMap<>();
        map.put("context",context);
        return  map;
    }


    // /cars/sell;low=34;brand=byd,audi,yd
    @GetMapping("/cars/{path}")
    public  Map carSell(@MatrixVariable("low") Integer low,
                        @MatrixVariable("brand") List<String> brands,
                        @PathVariable("path") String path){
        HashMap<String, Object> map = new HashMap<>();
        map.put("low",low);
        map.put("brand",brands);
        map.put("path",path);
        return map;

    }

    //  /boss/1;age=20/2;age=10
    @GetMapping("/boss/{bossId}/{empId}")
    public Map boss(@MatrixVariable(value = "age",pathVar = "bossId") Integer bossAge,
                    @MatrixVariable(value = "age",pathVar = "empId") Integer empAge){
        HashMap<String, Object> map = new HashMap<>();
        map.put("bossAge",bossAge);
        map.put("empAge",empAge);
        return map;
    }

}
